<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>透视相机</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }
    </style>
</head>

<body>
    <script type="module">
        //引入three
        import * as THREE from "three";

        //创建场景
        const scene = new THREE.Scene();

        //创建相机
        const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);

        //创建渲染器
        const renderer = new THREE.WebGLRenderer();
        renderer.setSize(window.innerWidth, window.innerHeight);
        document.body.appendChild(renderer.domElement);

        //创建立方体
        const geometry = new THREE.BoxGeometry(1, 1, 1);
        const material = new THREE.MeshBasicMaterial({ color: 0x00ff0 });
        const cube = new THREE.Mesh(geometry, material);
        //将创建好的立方体添加到场景内
        scene.add(cube);

        //将相机的z坐标调整到5
        camera.position.z = 5;

        //渲染场景
        function animate() {
            requestAnimationFrame(animate);
            renderer.render(scene, camera)
        }
        animate()
    </script>
</body>

</html>